package com.bungarus.group;

import com.bungarus.group.config.ShardingConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;


@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
@EnableAspectJAutoProxy
@Import(ShardingConfig.class)
public class BungarusGroupApplication {
    /**
     * Sharding-jdbc datasource
     */
	@Autowired
	private DataSource shardingDataSource;

    /**
     * JdbcTemplate for sharding-jdbc
     * @return
     * @throws Exception
     */
	@Bean("jdbcTemplate")
	public JdbcTemplate jdbcStandaloneTemplate() throws Exception {
		return new JdbcTemplate(shardingDataSource);

	}

	public static void main(String[] args) {
		SpringApplication.run(BungarusGroupApplication.class, args);
	}
}
